/**
* @file box3d.cpp
* August 11, 2008
* 
* @brief Defines a three-dimensional box that limits/bounds the geometric object
* 
* @author Andre Pereira (brabo@tecgraf.puc-rio.br)
* 
* @see Curve
*/


// includes
//----------
#include "box3d.h"


// class implementation
//----------------------

//
/////////////////////////////////////////////////////////////////////
Box3D::Box3D()
: m_isEmpty( true )
{
}


//
/////////////////////////////////////////////////////////////////////
Box3D::~Box3D()
{
}


//
/////////////////////////////////////////////////////////////////////
void
Box3D::update( double _x,
               double _y,
               double _z )
{
  if( m_isEmpty )
  {
    m_xmin = m_xmax = _x;
    m_ymin = m_ymax = _y;
    m_zmin = m_zmax = _z;
    m_isEmpty = false;
    return;
  }

  if( _x < m_xmin )
    m_xmin = _x;
  if( _y < m_ymin )
    m_ymin = _y;
  if( _z < m_zmin )
    m_zmin = _z;
  if( _x > m_xmax )
    m_xmax = _x;
  if( _y > m_ymax )
    m_ymax = _y;
  if( _z > m_zmax )
    m_zmax = _z;
}

//
/////////////////////////////////////////////////////////////////////
int
Box3D::get( double& _xmn,
            double& _ymn,
            double& _zmn,
            double& _xmx,
            double& _ymx,
            double& _zmx )
{
  _xmn = m_xmin;
  _ymn = m_ymin;
  _zmn = m_zmin;
  _xmx = m_xmax;
  _ymx = m_ymax;
  _zmx = m_zmax;
  return 1;
}

//
/////////////////////////////////////////////////////////////////////
int
Box3D::get( double data[6] )
{
  data[0] = m_xmin;
  data[1] = m_xmax;
  data[2] = m_ymin;
  data[3] = m_ymax;
  data[4] = m_zmin;
  data[5] = m_zmax;

  return 1;
}


//
/////////////////////////////////////////////////////////////////////
void
Box3D::clear()
{
  m_isEmpty = true;
}
//
/////////////////////////////////////////////////////////////////////
void 
Box3D::expande (double _factor)
{
	// center
	double cx = (m_xmax + m_xmin) * 0.5;
	double cy = (m_ymax + m_ymin) * 0.5;
	double cz = (m_zmax + m_zmin) * 0.5;

	// box
	double Lx = (m_xmax - m_xmin) * (1.0 + _factor * 0.01) * 0.5;
	double Ly = (m_ymax - m_ymin) * (1.0 + _factor * 0.01) * 0.5;
	double Lz = (m_zmax - m_zmin) * (1.0 + _factor * 0.01) * 0.5;

	m_xmin = cx - Lx;
	m_ymin = cy - Ly;
	m_zmin = cz - Lz;
	m_xmax = cx + Lx;
	m_ymax = cy + Ly;
	m_zmax = cz + Lz;
}
